package com.jltx.xq.relaxnewspro.database.collection;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Handler;

import com.jltx.xq.relaxnewspro.LeisureApplication;
import com.jltx.xq.relaxnewspro.database.DatabaseHelper;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by bo on 2017/4/14.
 */

public abstract class BaseCollectionCache<T> implements ICache<T> {

    protected DatabaseHelper mHelper;
    protected SQLiteDatabase db;

    protected List<T> mList = new ArrayList<>();

    protected Handler mHandler;

    public BaseCollectionCache(Handler mHandler) {
        this.mHandler = mHandler;
        mHelper = DatabaseHelper.instance(LeisureApplication.AppContext);
    }

    public void addToCollection(T object) {

    }

    @Override
    public void ececSQL(String sql) {
        db = mHelper.getWritableDatabase();
        db.execSQL(sql);
    }

    public List<T> getmList(){
         return mList;
     }

     public boolean hasData(){
         return !mList.isEmpty();
     }

     public void load(){

     }

     public void cache(){

     }

     protected Cursor query(String sql){
        return mHelper.getReadableDatabase().rawQuery(sql,null);
   }
}
